package com.cp.admin.modular.system.controller;

import com.cp.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.cp.admin.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.cp.admin.modular.system.model.Proclamation;
import com.cp.admin.modular.system.service.IProclamationService;

/**
 * 系统公告控制器
 *
 * @author fengshuonan
 * @Date 2019-03-20 22:14:11
 */
@Controller
@RequestMapping("/proclamation")
public class ProclamationController extends BaseController {

    private String PREFIX = "/system/proclamation/";

    @Autowired
    private IProclamationService proclamationService;

    /**
     * 跳转到系统公告首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "proclamation.html";
    }

    /**
     * 跳转到添加系统公告
     */
    @RequestMapping("/proclamation_add")
    public String proclamationAdd() {
        return PREFIX + "proclamation_add.html";
    }

    /**
     * 跳转到修改系统公告
     */
    @RequestMapping("/proclamation_update/{proclamationId}")
    public String proclamationUpdate(@PathVariable Long proclamationId, Model model) {
        Proclamation proclamation = proclamationService.selectById(proclamationId);
        model.addAttribute("item",proclamation);
        LogObjectHolder.me().set(proclamation);
        return PREFIX + "proclamation_edit.html";
    }

    /**
     * 获取系统公告列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return proclamationService.selectList(null);
    }

    /**
     * 新增系统公告
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Proclamation proclamation) {
        proclamationService.insert(proclamation);
        return SUCCESS_TIP;
    }

    /**
     * 删除系统公告
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long proclamationId) {
        proclamationService.deleteById(proclamationId);
        return SUCCESS_TIP;
    }

    /**
     * 修改系统公告
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Proclamation proclamation) {
        proclamationService.updateById(proclamation);
        return SUCCESS_TIP;
    }

    /**
     * 系统公告详情
     */
    @RequestMapping(value = "/detail/{proclamationId}")
    @ResponseBody
    public Object detail(@PathVariable("proclamationId") Long proclamationId) {
        return proclamationService.selectById(proclamationId);
    }
}
